package org.zhuzx.util;

import java.io.InputStream;
import java.util.*;

import javax.xml.stream.*;

/**
 * xml工具类
 * @author	zhuzx	2017年11月21日
 */
public class SimpleXmlUtil {
	
	public static Map<String,String> parseXmlToPlainTextMap(InputStream in) {
		try {
			Map<String, String> map = new LinkedHashMap<>();
			XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(in);
			while (reader.hasNext()) {
				int event = reader.next();
				if (event == XMLStreamConstants.START_ELEMENT) {
					if (reader.getLocalName().equals("text")) {
						map.put(reader.getAttributeValue(null, "id"), reader.getElementText());
					}
				}
			}
			in.close();
			return map;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public static Map<String,Map<String,String>> parseXmlToMap(InputStream in) {
		Map<String, Map<String,String>> map = new LinkedHashMap<>();
		
		return map;
	}
	
}